package com.cs342.uwosh.cloudycontacts.tasks.db;

import java.util.ArrayList;
import java.util.List;

import com.cs342.uwosh.cloudycontacts.Contact;
import com.cs342.uwosh.cloudycontacts.MainActivity;
import com.cs342.uwosh.cloudycontacts.R;
import com.cs342.uwosh.cloudycontacts.SqlConnect;


import android.os.AsyncTask;
import android.widget.ArrayAdapter;

public class GetContactsByCategoryTask extends AsyncTask<Integer, Object, ArrayList<Contact>>{

	@Override
	protected ArrayList<Contact> doInBackground(Integer... arg0) {
		SqlConnect db = MainActivity.db;
		return (ArrayList<Contact>)db.getContactsFromCategory(arg0[0]);
	}
	
	@Override
	protected void onPostExecute(ArrayList<Contact> arg0)
	{	
		ArrayList<Contact> contacts = arg0;

		if (MainActivity.CURRENT_THEME.equals(MainActivity.THEME_DEFAULT))
        {
            MainActivity.contactListAdapter = new ArrayAdapter<Contact>(MainActivity.mainContext, R.layout.list_item_theme_default, R.id.contactItem, contacts);
        }
        else if (MainActivity.CURRENT_THEME.equals(MainActivity.THEME_ONE))
        {
            MainActivity.contactListAdapter = new ArrayAdapter<Contact>(MainActivity.mainContext, R.layout.list_item_theme1_default, R.id.contactItem, contacts);
        }
        else if (MainActivity.CURRENT_THEME.equals(MainActivity.THEME_TWO))
        {
            MainActivity.contactListAdapter = new ArrayAdapter<Contact>(MainActivity.mainContext, R.layout.list_item_theme2_default, R.id.contactItem, contacts);
        }
        else if (MainActivity.CURRENT_THEME.equals(MainActivity.THEME_THREE))
        {
            MainActivity.contactListAdapter = new ArrayAdapter<Contact>(MainActivity.mainContext, R.layout.list_item_theme3_default, R.id.contactItem, contacts);
        }
        
        MainActivity.listOfContacts.setAdapter(MainActivity.contactListAdapter);
		
	}
}
